﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_login_register_layout.cshtml";
}

<div class="tab_btn_wrap">
    <span class="active" id="tab_phone">手机注册</span>
    <span id="tab_email">邮箱注册</span>
</div>
<span class="line_blue"></span>



<div class="form_wrap">

    <div class="reg_list" id="register">
        <div class="form-group">
            <label for="reg_input_name">用户名</label>
            <input type="tel" class="form-control" id="reg_input_name" onfocus="ClearError(this)" onblur="JudgmentExist(this)">
            <label class="error_lable" id="name_error"></label>
        </div>
        <!--    手机注册-->
        <div class="form-group" id="form_phone">
            <label for="reg_input_phone">手机号</label>
            <input type="tel" class="form-control" onfocus="ClearError(this)" onblur="Judge(this);JudgmentExist(this)" id="reg_input_phone">
            <label class="error_lable" id="phone_error"></label>
        </div>
        <!--    邮箱注册-->
        <div class="form-group form_hidden" id="form_email">
            <label for="reg_input_email">邮箱</label>
            <input type="email" class="form-control" onfocus="ClearError(this)" onblur="Judge(this);JudgmentExist(this)" id="reg_input_email">
            <label class="error_lable" id="email_error"></label>
        </div>
        <div class="form-group">
            <label for="reg_input_password">
                密码
                <span>（请设置包含数字、字母和符号的8~20位密码）</span>
            </label>
            <input type="password" class="form-control" onfocus="ClearError(this)" onblur="JudgeSame(this)" id="reg_input_password">
            <label class="error_lable" id="error_password"></label>
        </div>
        <div class="form-group">
            <label for="reg_input_password_ag">确认密码</label>
            <input type="password" class="form-control" onfocus="ClearError(this)" onblur="JudgeSame(this)" id="reg_input_password_ag">
            <label class="error_lable" id="error_password_ag"></label>

        </div>
        <div class="checkbox">
            <i Is-select="false" id="select" onclick="ChangeSelect(this)"></i>
            <span>我接受</span>
            <a href="#">问卷网服务协议</a>
        </div>
        <label class="error_lable" style="font-size:15px;" id="error_message"></label>
        <button id="register" type="submit" class="btn btn-primary btn_register" onclick="register()">立即注册</button>
    </div>
</div>

<div class="link_choose">
    <span>第三方登录&nbsp;或</span>
    <a href="~/Login/Index" class="link_register">问卷网账号登录</a>
</div>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    function register() {

        //是否接受协议
        var Is_select = document.getElementById("select").getAttribute("Is-select");

        if (document.getElementById("reg_input_password").value != document.getElementById("reg_input_password_ag").value) {
            console.log("密码不一致");
            return;
        }
        var account;
        var password;
        var name;
        var x = document.getElementById("tab_phone");
        if (x.className == "active") {
            account = document.getElementById("reg_input_phone").value;
        }
        else {
            account = document.getElementById("reg_input_email").value;
        }
        name = document.getElementById("reg_input_name").value;
        password = document.getElementById("reg_input_password_ag").value
        if (account == "" || password == "" || name == "") {
            return;
        }
        if (email_error.style.display == "block" || name_error.style.display == "block" || phone_error.style.display == "block" || error_password.style.display == "block" || error_password.style.display == "block" || error_password_ag.style.display == "block") {
            return;
        }

        if (Is_select == "false") {
            error_message.innerHTML = "请确认接受服务协议!";
            error_message.style.display = "block";
            return;
        }

        axios.post('../Register/register_info', {
            account: account, 
            password: password,
            name: name
             })
            .then(function (response) {
                console.log(response.data);
                var id = response.data
                if (id != "0") {
                    window.location.href = "../ProjectList/Index?id="+id;
                }

        })
        .catch(function (error) {
          console.log(error);
        });


    }
</script>
